﻿using System;
using System.Net;
using System.Web.Mvc;
using Enyim.Caching;
using SilenthinkContract;
using SilenthinkContract.Domain;

namespace Web.Manage.Controllers
{
    public class ProductAttributeValueController : BaseController
    {
        public ProductAttributeValueController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient) : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        public ActionResult Index(string productCategoryCode = "", string attributeNameCode = "")
        {
            ViewBag.ProductCategoryCode = productCategoryCode;
            ViewBag.AttributeNameCode = attributeNameCode;

            var model =StoreService.GetProductAttributeValue(productCategoryCode, true, new[] { attributeNameCode });
            return View(model);
        }
        public ActionResult Create(string productCategoryCode = "", string attributeNameCode = "")
        {
            ViewBag.ProductCategoryCode = productCategoryCode;
            ViewBag.AttributeNameCode = attributeNameCode;

            return View();
        }
        [HttpPost]
        public ActionResult Create(ProductAttributeValue model)
        {
            model.DisplayOrder = 0;
            model.PreSelected = false;
            var date = DateTime.Now;
            model.CreatedBy = "admin";
            model.CreatedOn = date;
            var result =StoreService.CreateProductAttributeValue(model);
            return Json(result ? HttpStatusCode.OK : HttpStatusCode.Ambiguous, result ? "添加成功" : "添加失败", "/ProductAttributeValue/", "/ProductAttributeValue/?productCategoryCode=" + model.ProductCategoryCode + "&attributeNameCode="+model.AttributeNameCode);
        }

    }
}
